<!doctype html>
<html>
<head>    
	<meta charset="utf-8">    
	<title>商品计算器（两件商品）</title>
</head>
<body>    
	<form action="" method="post">        
		<table width="400" border="1">            
			<caption>新华书店计算器</caption>           
			 <tr>                
			 	<td>文具商品1单价</td>                
			 	<td><input type="text" name="p1" id="textfield"></td></tr>            
			 	<tr>                
			 		<td>文具商品1数量</td>                
			 		<td><input type="text" name="num1" id="textfield2">
			 		</td>            
			 	</tr>            
			 	<tr>                
			 		<td>文具商品1折扣</td>               
			 		 <td><input type="text" name="zk1" id="textfield3"></td>            
			 		</tr>            
			 		<tr>               
			 		 <td>文具商品2单价</td>               
			 		  <td><input type="text" name="p2" id="textfield3"></td>            
			 		</tr>            
			 		<tr>               
			 		 <td>文具商品2数量</td>                
			 		 <td><input type="text" name="num2" id="textfield4"></td>           
			 		  </tr>           
			 		   <tr>                
			 		   	<td>文具商品2折扣</td>                
			 		   	<td><input type="text" name="zk2" id="textfield3"></td>            
			 		   </tr>            
			 		   <tr>                
			 		   	<td>文具商品3单价</td>                
			 		   	<td><input type="text" name="p3" id="textfield"></td>            
			 		   </tr>            
			 		   <tr>               
			 		    <td>文具商品3数量</td>               
			 		     <td><input type="text" name="num3" id="textfield2"></td>            
			 		 </tr>            
			 		 <tr>                
			 		 	<td>文具商品3折扣</td>               
			 		 	 <td><input type="text" name="zk3" id="textfield3"></td>           
			 		 	  </tr>            
			 		 	  <tr>               
			 		 	   <td>文具商品4单价</td>               
			 		 	    <td><input type="text" name="p4" id="textfield"></td>            
			 		 	</tr>            
			 		 	<tr>                
			 		 		<td>文具商品4数量</td>               
			 		 		 <td><input type="text" name="num4" id="textfield2"></td>            
			 		 		</tr>            
			 		 		<tr>                
			 		 			<td>文具商品4折扣</td>               
			 		 			 <td><input type="text" name="zk4" id="textfield3"></td>           
			 		 			  </tr>           
			 		 			   <tr>               
			 		 			    <td>文具商品5单价</td>               
			 		 			     <td><input type="text" name="p5" id="textfield">
			 		 			     </td>            
			 		 			 </tr>           
			 		 			  <tr>                
			 		 			  	<td>文具商品5数量</td>           
			 		 			  	<td><input type="text" name="num5" id="textfield2"></td>         
			 		 			  </tr>          
			 		 			  	<tr>               
			 		 			  	 <td>文具商品5折扣</td>                
			 		 			  	 <td><input type="text" name="zk5" id="textfield3"></td>            
			 		 			  	</tr>            
			 		 			  	<tr>                
			 		 			  		<td colspan="2" align="center"><input type="submit" name="cal" id="button" value="计算"></td>     
			 		 			  	</tr>        
			 </table>   
        </form>
 <?php
 class price {   
  private $num1;    
  private $num2;    
  private $num3;    
  private $num4;   
  private $num5;    
   private $p1;     
   private $p2; 
   private $p3;  
   private $p4;   
   private $p5; 
   private $zk1;     
   private $zk2; 
   private $zk3;  
   private $zk4;   
   private $zk5;
   function __construct($n1, $n2, $n3, $n4, $n5, $n6) {       
   $this->num1 = $n1;        
   $this->num2 = $n2;        
   $this->p1 = $n3;        
   $this->p2 = $n4;
   $this->zk1 = $n5;        
   $this->zk2 = $n6;     
}    
function Cal(){        
            $sum = $this->num1 * $this->p1 * $this->zk1 + $this->num2 * $this->p2 * $this->zk2;        
            return $sum;   
}
}
if (isset($_POST["cal"])) {    
$p1 = $_POST["p1"];     
$p2 = $_POST["p2"];     
$num1 = $_POST["num1"];    
$num2 = $_POST["num2"];  
$zk1  = $_POST["zk1"]; 
$zk2  = $_POST["zk2"]; 
$calculator = new price($num1, $num2, $p1, $p2, $zk1, $zk2);    
$sum = $calculator->Cal();    
echo "<br>";   
 echo "购买商品1:" . $num1 . "件，单价:" . $p1 . "元，折扣:" . $zk1 . "折<br>";    
 echo "购买商品2:" . $num2 . "件，单价:" . $p2 . "元，折扣:" . $zk2 . "折<br>";   
 echo "总计为：" . $sum . "元<br>";
}
?>
</body>
</html>
